<template>
<<<<<<< HEAD
  <div class="search-history">   
    <div class="history box">
      <div class="title">
        <span>最近搜索</span>
        <van-icon class='del' name='delete-o'/> 
      </div>
        <ul class='content'>
          <li @click='clickHandler'>
            内容11</li>
         <li>
            内容22
          </li>
        </ul> 
    </div>

        <div class="hot box">
      <div class="title">
        <span>热门搜索</span>
        <span @click='isShow= !isShow'>{{isShow?"隐藏":"显示"}}</span>
      </div>
        <ul class='content' v-if='isShow'>
          <li>
            内容1
          </li>
          <li>
            内容2
          </li>
        </ul> 
        <div v-else class='hid'>
          已经隐藏热门搜索
        </div> 
    </div>

  </div>

</template>
<script setup lang='ts'>
import search from 'vant/lib/search'
import {ref} from 'vue'
import{useRouter, type Router} from 'vue-router'

const $router:  Router= useRouter()

const isShow = ref<boolean>(true) 

//点击按钮跳转路由，需要跳转分类也
  const clickHandler =(e: Event)=>{
    const text = (e.target as HTMLElement ).innerText

    // 需要跳转路由， 需要携带text去商品列表也
    $router.push({path:'/list',query:{search: text}})
  }
=======
  <div class="sdy-search-history">
    <div v-if="historyList.length" class="history box">
      <div class="title">
        <span>最近搜索</span>
        <van-icon @click="clearHistoryHandler" class="del" name="delete-o" />
      </div>
      <ul class="content">
        <li
          v-for="item in historyList"
          @click="clickHandler">{{ item }}</li>
      </ul>
    </div>
    <div class="hot box">
      <div class="title">
        <span>热门搜索</span>
        <span @click="isShow = !isShow">{{ isShow ? '隐藏' : '显示' }}</span>
      </div>
      <ul v-if="isShow" class="content">
        <li
          v-for="item in hotList"
          :key="item.wordid"
          @click="clickHandler"
          >
          {{ item.keyword }}
        </li>
      </ul>
      <div v-else class="hid">
        已经隐藏搜索发现
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRouter, type Router } from 'vue-router'
// 导入请求 api
import { hotSearchApi } from '@/api/goods'
// 导入对应的 ts 接口
import type { MyHotSearchItem } from '@/config/interface'


// 历史记录相关
const $router: Router = useRouter()

// 需要一个数组保存历史记录
const historyList = ref(JSON.parse(window.localStorage.getItem('history') as string) || [])

// 准备一个变量, 控制 隐藏 显示
const isShow = ref<boolean>(true)

// 按钮点击的时候跳转到分类页面
const clickHandler = (e: Event) => {
  const text = (e.target as HTMLElement).innerText

  // 需要跳转路由, 需要携带 text 去到商品列表页
  $router.push({ path: '/list', query: { search: text } })
}

// 点击历史记录边上的删除按钮
const clearHistoryHandler = () => {
  // 删除 lcoalStorage 内的 history 一项
  window.localStorage.removeItem('history')
  historyList.value = []
}



// 热门搜索相关
// 准备一个变量保存热门搜索列表
const hotList = ref<MyHotSearchItem[]>([])

// 挂载完毕后请求数据
onMounted(async () => {
  const res = await hotSearchApi()
  hotList.value = res.data
})
>>>>>>> 24d0d7191411ba3bacecf3c116acfb924e67c6fb


</script>

<<<<<<< HEAD
<style scoped lang="scss"> 
  .search-history{
    height: 100%;
    box-sizing: border-box;
    padding: 15px;

    > .box {
      margin-bottom: 10px;

      > .title{
        display: flex;
        justify-content: space-between;
        > .del{
          font-size: 22px;
        }
      }
      > ul{
        display: flex;
        flex-wrap: wrap;
        margin-top: 2px;
        > li {
          background: #c4c4c4;
          color:#fff;
          padding: 2px 3px;
          margin: 0 2px;
          border-radius: 5px;
          
        }
      }
      > .hid{
        height:100%;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
  }
</style>
=======
<style scoped lang="scss">
.sdy-search-history {
  height: 100%;
  box-sizing: border-box;
  padding: 15px;

  > .box {
    margin-bottom: 30px;

    > .title {
      display: flex;
      justify-content: space-between;

      .del {
        font-size: 20px;
      }
    }

    > ul {
      display: flex;
      flex-wrap: wrap;
      margin-top: 5px;

      > li {
        background-color: #c4c4c4;
        color: #fff;
        padding: 2px 3px;
        margin: 0 2px;
      }
    }

    > .hid {
      height: 100px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}
</style>
>>>>>>> 24d0d7191411ba3bacecf3c116acfb924e67c6fb
